package com.zr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.model.UserModel;
import com.zr.util.JdbcUtil;

public class DatePswDao {
    public UserModel  validateUser(int  sid){
    String sql="select * from user  where sid=?";
    UserModel usermd= new  UserModel();
	  Connection con=JdbcUtil.getDBConnection();
      try {
		PreparedStatement  pst = con.prepareStatement(sql);
	     pst.setInt(1,sid);
	   ResultSet rs=pst.executeQuery();
	   if(rs.next()){
		   
		   usermd.setSpwt(rs.getString("spwt"));
	   };
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}finally {
		JdbcUtil.closedConnection(con);
		
	}
      return usermd;
    }
    public boolean Datepsw(UserModel user){
    	boolean    flag=false;
    	String sql="update user set spwt=? where sid=?";
    	Connection con=JdbcUtil.getDBConnection();
    	try {
			PreparedStatement pst=con.prepareStatement(sql);
			pst.setString(1,user.getSpwt());
			pst.setInt(2, user.getSid());
			int  pt= pst.executeUpdate();
			if(pt>0){
				flag=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			JdbcUtil.closedConnection(con);
			
		}
    	return flag;
    }
}
